package com.cool.reggie.config;

import com.baomidou.mybatisplus.annotation.DbType;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.github.yitter.idgen.YitIdHelper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author ifredomvip@gmail.com
 * @Date 2022/6/30 14:55
 * @Version 1.0.0
 * @Description
 **/
@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

//    @Bean
//    public IdentifierGenerator idGenerator() {
//
//        class CustomIdGenerator implements IdentifierGenerator {
//            @Override
//            public Long nextId(Object entity) {
//                //可以将当前传入的class全类名来作为bizKey,或者提取参数来生成bizKey进行分布式Id调用生成.
//                String bizKey = entity.getClass().getName();
//                //根据bizKey调用分布式ID生成
//                long id = YitIdHelper.nextId();
//
//                System.out.println(IdWorker.getId());
//                System.out.println("生成Id"+id);
//                //返回生成的id值即可.
//                return id;
//            }
//        }
//
//        return new CustomIdGenerator();
//    }
}
